#!/bin/bash

set +e

echo "Usage: #./builder_private [notary version]"
if [ -z $1 ]; then
  error "Please set the 'version' variable"
  exit 1
fi

VERSION="$1"
SIGNER_PHOTONIMAGE=vmware/notary-photon:signer-$VERSION
SERVER_PHOTONIMAGE=vmware/notary-photon:server-$VERSION

set -e

# the temp folder to store binary file...
mkdir -p binary
rm -rf binary/notary-server || true
rm -rf binary/notary-signer || true

cd `dirname $0`
cur=$PWD

# It won't store the notray binary in Harbor repo, so far it's a temporary solution..
TEMP=`mktemp -d /$TMPDIR/notary.XXXXXX`
git clone https://github.com/reasonerjt/notary-photon $TEMP

echo 'build the notary binary bases on the golang:1.7.3...'

cp -rf $TEMP/migrations .
cp $TEMP/migrate .
cp $TEMP/notary-server ./binary/
cp $TEMP/notary-signer ./binary/

docker build -f server.Dockerfile -t $SERVER_PHOTONIMAGE .
docker build -f signer.Dockerfile -t $SIGNER_PHOTONIMAGE .